﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SaleManagement.Controllers;
using System.IO;
using System.Drawing.Imaging;

namespace SaleManagement.modules
{
    public partial class usShopInfo : UserControl
    {
        private ShopsController clShop;
        public usShopInfo()
        {
            clShop = new ShopsController();
            InitializeComponent();
            clShop.Setform(this);
        }

        private void bttAddShop_Click(object sender, EventArgs e)
        {
            MemoryStream stream = new MemoryStream();
            imgpreview.Image.Save(stream,ImageFormat.Jpeg);
            byte[] img = stream.ToArray();
            if(clShop.Post_AddShop(tbxShopName.Text, tbxShopAddress.Text, tbxShopPhone.Text, tbxShopWebsite.Text, img))
            {
                MessageBox.Show(clShop.mesage);
                tbxShopAddress.Text = tbxShopName.Text = tbxShopPhone.Text = tbxShopWebsite.Text = "";
                imgpreview.Image = null;
            }
            else
            {
                MessageBox.Show(clShop.mesage);
            }
        }
        private void btnSelectLogo_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            if (ofd.FileName != null)
            {
                imgpreview.Image = Image.FromFile(ofd.FileName);
                imgpreview.Name = ofd.FileName.ToString();
            }
        }

    }
}
